﻿using ARchGL.Platform.Configuration;
using ARchGL.Platform.Core;
using ARchGL.Platform.Web;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Npgsql;
using NpgsqlTypes;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace ARchGL.Platform.Utils
{
    public class CustomExpressionVisitor : ExpressionVisitor
    {
        /// <summary>
        /// 重写 VisitMember 用于获取表达式树
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        protected override Expression VisitMember(MemberExpression node)
        {
            if (node.Expression is ConstantExpression)
            {
                object obj = (node.Expression as ConstantExpression).Value;
                if (node.Member is FieldInfo)
                {
                    var value = (node.Member as FieldInfo).GetValue(obj);
                    return Expression.Constant(value, node.Type);
                }
                else if (node.Member is PropertyInfo)
                {
                    var value = (node.Member as PropertyInfo).GetValue(obj);
                    return Expression.Constant(value, node.Type);
                }
            }
            return base.VisitMember(node);
        }

        public string GetPropertys(Expression<Func<HoistRealDatas, bool>> func)
        {
            var visitor = new CustomExpressionVisitor();
            var exp = visitor.Visit(func) as LambdaExpression;
            return exp.Body.ToString();
        }
    }
}
